var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2kc = require("kc");
var $2KDefine = require("KDefine");
var $2StateComponent = require("StateComponent");
var $2ZombieMgr = require("ZombieMgr");
var $2PlantBase = require("PlantBase");
var $2BundleManager = require("BundleManager");
var $2ExcelManager = require("ExcelManager");
var $2BulletMgr = require("BulletMgr");
var $2SceneStage = require("SceneStage");
var $2AudioManager = require("AudioManager");
var $2UserDataManager = require("UserDataManager");
var $2DataManager = require("DataManager");
var $2PoolManager = require("PoolManager");
var $2BowlingUI = require("BowlingUI");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_Zombie = /* */function (_o$default3) {
  babel_inherits(b, _o$default3);
  var _super107 = babel_createSuper(b);
  function b() {
    var _this250;
    babel_classCallCheck(this, b);
    _this250 = _super107.apply(this, arguments);
    _this250.id = 1;
    _this250.speed = 1;
    _this250.speed2 = 1;
    _this250._hp = 1;
    _this250.allHp = 1;
    _this250.damage = 2;
    _this250.hitInteval = 1;
    _this250.wave = 1;
    _this250.inUse = false;
    _this250.dragon = null;
    _this250.row = -1;
    _this250.flash = 0;
    _this250.rate = 0;
    _this250.frozenTimes = 0;
    _this250.huangyouTime = 0;
    _this250._time = 1;
    _this250.allequipHp = 0;
    _this250._equipHp = 0;
    _this250._attackNums = 0;
    _this250.equipmentSkin = "";
    _this250.nowAnimationName = "";
    _this250.count = 1;
    _this250.blq_js = [];
    _this250.ani = {
      move: "zou",
      attack: "kenyao",
      dead: "die"
    };
    _this250.attackTarget = null;
    _this250.canContinueHurt = true;
    return _this250;
  }
  babel_createClass(b, [{
    key: "time",
    get() {
      return this._time;
    },
    set(e) {
      this._time = e;
      this.dragon.timeScale = this.time;
    }
  }, {
    key: "equipHp",
    get() {
      return this._equipHp;
    },
    set(e) {
      this._equipHp = e;
    }
  }, {
    key: "attackNums",
    get() {
      return this._attackNums;
    },
    set(e) {
      this._attackNums = e;
    }
  }, {
    key: "hp",
    get() {
      return this._hp;
    },
    set(e) {
      this._hp = e;
    }
  }, {
    key: "unuse",
    value: function unuse() {
      this.inUse = false;
      this.stop();
    }
  }, {
    key: "reuse",
    value: function reuse() {
      this.inUse = false;
    }
  }, {
    key: "onLoad",
    value: function onLoad() {
      this.regState($2KDefine.State.move, this.stateMove);
      this.regState($2KDefine.State.moveing, this.stateMove);
      this.regState($2KDefine.State.hurt, this.stateHurt);
      this.regState($2KDefine.State.hurting, this.stateHurt);
      this.regState($2KDefine.State.dead, this.stateDead);
      this.regState($2KDefine.State.deading, this.stateDead);
      this.regState($2KDefine.State.attack, this.stateAttack);
      this.regState($2KDefine.State.attacking, this.stateAttack);
    }
  }, {
    key: "reduceHp",
    value: function reduceHp(e) {
      this.blq_js = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.blq_js);
      for (var _t83 in this.blq_js) {
        if (e === this.blq_js[_t83].zombieId) {
          return this.blq_js[_t83];
        }
      }
      return null;
    }
  }, {
    key: "daiji",
    value: function daiji() {
      this.node.getChildByName("zombie").getComponent(sp.Skeleton).setAnimation(0, this.ani.move, true);
    }
  }, {
    key: "reset",
    value: function reset(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
      if (e > 10 && e < 16) {
        this.ani.move = "walk";
        $2kc.default.log("切换走动作为walk");
      }
      this.dragon = this.node.getChildByName("zombie").getComponent(sp.Skeleton);
      var a = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.zombieTable)[e];
      this.id = a.id;
      var n = this.reduceHp(this.id);
      this.count = n ? n.num : 1;
      this.hp = a.hp * $2UserDataManager.default.instance.chapter * $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.levelTable)[$2ZombieMgr.default.instance().level].hp[t];
      this.equipHp = a.equipmentHp * $2UserDataManager.default.instance.chapter * $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.levelTable)[$2ZombieMgr.default.instance().level].hp[t];
      this.allHp = this.hp;
      this.allequipHp = this.equipHp;
      this.equipmentSkin = a.equipmentSkin;
      this.damage = a.damage * $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.levelTable)[$2ZombieMgr.default.instance().level].att[t];
      this.speed = a.speed * $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.levelTable)[$2ZombieMgr.default.instance().level].speed[t];
      this.speed2 = this.speed;
      this.hitInteval = a.hitInteval;
      this.node.scale = a.scale;
      this.buffRest();
      return this;
    }
  }, {
    key: "setSkin",
    value: function setSkin() {
      var _this251 = this;
      var e = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.zombieTable)[this.id];
      if ($2BundleManager.default.instance.getBundleRes("Spine", "zombie/" + e.dragonName + "/" + e.dragonName, sp.SkeletonData)) {
        this.dragon.skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "zombie/" + e.dragonName + "/" + e.dragonName, sp.SkeletonData);
        this.dragon.defaultSkin = e.defaultSkin;
        this.dragon.setSkin(e.defaultSkin);
      } else {
        $2BundleManager.default.instance.loadBundleRes("Spine", "zombie/" + e.dragonName + "/" + e.dragonName, sp.SkeletonData, function () {
          _this251.dragon.skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "zombie/" + e.dragonName + "/" + e.dragonName, sp.SkeletonData);
          _this251.dragon.defaultSkin = e.defaultSkin;
          _this251.dragon.setSkin(e.defaultSkin);
        });
      }
    }
  }, {
    key: "buffRest",
    value: function buffRest() {
      this.time = 1;
      this.frozenTimes = 0;
      this.flash = 0;
      this.rate = 0;
      this.huangyouTime = 0;
      this.attackNums = 0;
      this.attackTarget = null;
      this.canContinueHurt = true;
      this._material = this.dragon.getMaterial(0);
      this.node.getChildByName("huangyou").active = false;
      this._material.setProperty("u_rate", 0);
      this._material.setProperty("ucolor", cc.color(255, 255, 255));
    }
  }, {
    key: "show",
    value: function show(e, t, a) {
      var n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
      this.inUse = true;
      this.node.opacity = 255;
      this.node.getChildByName("zombie").opacity = 255;
      this.node.setPosition(t);
      this.node.parent = e;
      this.node.zIndex = $2KDefine.ZIndex.enemy - this.row;
      this.wave = a;
      if (n) {
        this.setState($2KDefine.State.pause);
      } else {
        this.setState($2KDefine.State.move);
      }
      this.setSkin();
    }
  }, {
    key: "frozenNormal",
    value: function frozenNormal() {
      this.frozenTimes--;
      if (this.frozenTimes <= 0) {
        this._material.setProperty("ucolor", cc.color(255, 255, 255));
        this._material.setProperty("u_rate", 0);
        this.rate = 0;
        this.flash = 0;
        this.becomeNormal();
      }
    }
  }, {
    key: "frozen",
    value: function frozen() {
      if (this.inUse) {
        if (this.frozenTimes <= 0) {
          this._material.setProperty("ucolor", cc.color(15, 0, 255)), this.rate = .4, this.time *= .6;
        }
        this.frozenTimes = 3;
        this.unschedule(this.frozenNormal);
        this.schedule(this.frozenNormal, 1, 3);
      }
    }
  }, {
    key: "becomeNormal",
    value: function becomeNormal() {
      this.time = 1;
      this.frozenTimes > 0 && (this.time *= .6);
      this.huangyouTime > 0 && (this.time = 0);
    }
  }, {
    key: "recoverHuangyou",
    value: function recoverHuangyou() {
      this.huangyouTime--;
      if (0 == this.huangyouTime) {
        this.node.getChildByName("huangyou").active = false;
        this.becomeNormal();
      }
    }
  }, {
    key: "huangyou",
    value: function huangyou() {
      if (this.inUse) {
        this.node.getChildByName("huangyou").active = true;
        this.huangyouTime = 3;
        this.unschedule(this.recoverHuangyou);
        this.schedule(this.recoverHuangyou, 1, 3);
        this.time = 0;
      }
    }
  }, {
    key: "hurt",
    value: function hurt(e, t, a) {
      var n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
      var i = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
      var o = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
      if (this.inUse) {
        if ("" != t && t) {
          var _e134 = $2BulletMgr.default.instance().getEffect(t);
          _e134.scale = a;
          _e134.parent = this.node;
          _e134.x = n;
          _e134.y = i;
          var _s19 = _e134.getComponent(sp.Skeleton);
          _s19.setAnimation(0, "newAnimation", false);
          _s19.setCompleteListener(function () {
            _s19.setCompleteListener(null);
            _e134.scale = 1;
            $2BulletMgr.default.instance().removeEffect(_e134);
          });
        }
        this.hp -= e;
        if (this.hp <= 0) {
          this.setState($2KDefine.State.dead);
        } else {
          this.flash = .7;
        }
      }
    }
  }, {
    key: "bomb",
    value: function bomb() {
      var _this252 = this;
      this.inUse = false;
      $2AudioManager.default.instance.stopEffect($2KDefine.AudioName.ZombieAttackEff + this.node.uuid);
      this.node.getChildByName("zombie").opacity = 0;
      var e = cc.instantiate($2PoolManager.default.instance.getPoolNode("zombieBomb"));
      e.parent = this.node;
      e.getComponent(sp.Skeleton).setAnimation(0, "siwang", false);
      e.getComponent(sp.Skeleton).setCompleteListener(function () {
        $2PoolManager.default.instance.putPoolNode(e);
        e.getComponent(sp.Skeleton).setCompleteListener(null);
        $2ZombieMgr.default.instance().removeFromMap(_this252);
        $2ZombieMgr.default.instance().removeNode(_this252);
      });
    }
  }, {
    key: "stop",
    value: function stop() {
      this.inUse = false;
      this.setState($2KDefine.State.idle);
    }
  }, {
    key: "move",
    value: function move() {
      if (!(!this.inUse || this.hp <= 0)) {
        this.node.color = cc.Color.WHITE;
        this.setState($2KDefine.State.move);
      }
    }
  }, {
    key: "onCollisionEnter",
    value: function onCollisionEnter(e, t) {
      if (!(!this.inUse || this.hp <= 0)) {
        if (e.tag == $2KDefine.Tag.car) {
          this.hurt(99999);
        } else if (e.tag == $2KDefine.Tag.plant) {
          this.attackNums++, this.state != $2KDefine.State.attacking && this.setState($2KDefine.State.attack);
        }
      }
    }
  }, {
    key: "onCollisionStay",
    value: function onCollisionStay(e, t) {
      var _this253 = this;
      if (this.inUse && !(this.hp <= 0) && e.tag === $2KDefine.Tag.plant) {
        var _t84 = e.node.getComponent($2PlantBase.default);
        if (!_t84.inUse || !this.canContinueHurt) {
          return;
        }
        this.canContinueHurt = false;
        this.attackTarget = _t84;
        this.attackTarget.hurt(this.damage);
        $2AudioManager.default.instance.playEffect($2KDefine.AudioName.ZombieAttackEff, 1, false, false, this.node.uuid);
        this.scheduleOnce(function () {
          if (_this253.hp <= 0) {
            _this253.unscheduleAllCallbacks();
          } else {
            _this253.canContinueHurt = true;
          }
        }, this.hitInteval / this.time);
      }
    }
  }, {
    key: "onCollisionExit",
    value: function onCollisionExit(e, t) {
      !this.inUse || this.hp <= 0 || e.tag === $2KDefine.Tag.plant && (this.attackNums--, 0 == this.attackNums && (this.setState($2KDefine.State.move), $2AudioManager.default.instance.stopEffect($2KDefine.AudioName.ZombieAttackEff + this.node.uuid)));
    }
  }, {
    key: "moveAni",
    value: function moveAni() {
      this.nowAnimationName = this.ani.move;
      this.dragon.setAnimation(0, this.ani.move, true);
    }
  }, {
    key: "stateMove",
    value: function stateMove(e) {
      if (this.state === $2KDefine.State.move) {
        this.state = $2KDefine.State.moveing;
        this.moveAni();
        this.speed2 = this.speed;
      }
    }
  }, {
    key: "pause",
    value: function pause() {
      this.inUse = false;
      this.dragon.paused = true;
    }
  }, {
    key: "resume",
    value: function resume() {
      this.inUse = true;
      this.dragon.paused = false;
    }
  }, {
    key: "stateDead",
    value: function stateDead(e) {
      var _this254 = this;
      if (this.state === $2KDefine.State.dead) {
        0 == this.dragon.timeScale && (this.dragon.timeScale = 1);
        $2UserDataManager.default.instance.taskInfo[1].progress++;
        this.node.getChildByName("huangyou").active = false;
        $2AudioManager.default.instance.stopEffect($2KDefine.AudioName.ZombieAttackEff + this.node.uuid);
        this.hp = 0;
        this.speed2 = 0;
        this.state = $2KDefine.State.deading;
        this.inUse = false;
        $2ZombieMgr.default.instance().removeFromMap(this);
        this.deadAni();
        this.unscheduleAllCallbacks();
        this.dragon.setCompleteListener(function () {
          _this254.dragon.setCompleteListener(null);
          $2ZombieMgr.default.instance().removeNode(_this254);
        });
      }
    }
  }, {
    key: "deadAni",
    value: function deadAni() {
      this.nowAnimationName = this.ani.dead;
      this.dragon.setAnimation(0, this.ani.dead, false);
    }
  }, {
    key: "stateHurt",
    value: function stateHurt(e) {
      this.state === $2KDefine.State.hurt && (this.state = $2KDefine.State.hurting);
    }
  }, {
    key: "attackAni",
    value: function attackAni() {
      this.nowAnimationName = this.ani.attack;
      this.dragon.setAnimation(0, this.ani.attack, true);
    }
  }, {
    key: "stateAttack",
    value: function stateAttack(e) {
      if (this.state === $2KDefine.State.attack) {
        this.state = $2KDefine.State.attacking;
        this.speed2 = 0;
        this.attackAni();
      }
    }
  }, {
    key: "update",
    value: function update(e) {
      if (this.inUse) {
        if (0 != this.speed2) {
          this.node.x -= this.speed2 * this.time * e * 50, this.node.x < -560 && (this.speed2 = 0, $2DataManager.default.instance.is_bowling ? $2BowlingUI.default.instance.lose() : $2SceneStage.default.instance.lose());
        }
        this.updateFrame(e);
        if (this.flash > this.rate) {
          if (this.hp > 0) {
            this.flash -= e, this.flash < this.rate && (this.flash = this.rate), this._material.setProperty("u_rate", this.flash);
          } else {
            this._material.setProperty("u_rate", 0), this._material.setProperty("ucolor", cc.color(255, 255, 255));
          }
        }
      }
    }
  }, {
    key: "onDestroy",
    value: function onDestroy() {
      $2AudioManager.default.instance.stopEffect($2KDefine.AudioName.ZombieAttackEff + this.node.uuid);
    }
  }]);
  return b;
}($2StateComponent.default);
def_Zombie = cc__decorate([ccp_ccclass], def_Zombie);
exports.default = def_Zombie;